<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet"
	href="${pageContext.request.contextPath }/layui/layui_2/layui/css/layui.css"
	media="all">
	<style type="text/css">
        .layui-table-cell {
            height: 50px;
            line-height: 55px;
            text-align: center;
        }
    </style>
</head>
<body>
	<br/>
	<button class="layui-btn" id="save_dept_button">
  		<i class="layui-icon">&#xe608;</i>添加
	</button>
	<table class="layui-table" id="dept" lay-filter="dept_table"></table>
	<script src="${pageContext.request.contextPath }/layui/layui_2/layui/layui.js"></script>
	<script>
		layui.use(['form','element','jquery','table','layer'], function() {
			var form = layui.form,
				element = layui.element,
				$ = layui.jquery,
				table = layui.table,
				layer = layui.layer;
			
			var cols = [ [ {
				field : 'e_id',
				align : 'center',
				title : '员工编号',
				width : 160
			}, {
				field : 'e_truename',
				align : 'center',
				title : '员工真实姓名',
				width : 160
			}, {
				field : 'PName',
				align : 'center',
				title : '所在部门',
				width : 160
			}, {
				field : 'e_loginname',
				title : '登录名',
				align : 'center',
				width : 160
			}, {
				field : 'e_psw',
				align : 'center',
				title : '登录密码',
				width : 160
			}, {
				field : 'e_sex',
				align : 'center',
				title : '员工性别',
				width : 160,
				templet: '#sex'
			}, {
				field : 'e_img',
				align : 'center',
				title : '员工头像',
				width : 160,
				templet: '<div><img src="{{d.e_img}}" style="width: 50px;height: 50px;"/></div>'
			}, {
				field : 'e_flag',
				align : 'center',
				title : '员工类别',
				width : 160,
				templet: '#flag'
			}, {
				field : 'e_admin',
				align : 'center',
				title : '权限级别',
				width : 160,
				templet: '#admin'
			}, {
				title : '撤销部门',
				align : 'center',
				toolbar : '#operation',
				width : 265
			} ] ];
			
			//方法级渲染
			table.render({
				elem : '#dept',
				url : '${pageContext.request.contextPath }/empAction_findincumbencyByPage.action',
				cols : cols,
				id : 'testReload',
				limit: 10,
			    limits: [10, 30, 50],
				page : true
			});
			
			$('#save_dept_button').click(function(){
				layer.open({
					type: 2,
					title: '添加员工',
					skin: 'layui-layer-molv',
					shadeClose: true,
					shade: 0.5,
					area: ['600px', '700px'],
					content: '${pageContext.request.contextPath }/page_emp_addEmp'
				})
			});
			
			//监听工具条
			table.on('tool(dept_table)', function(obj){
			    var data = obj.data;
			    var id = data.e_id;
			    if(obj.event === 'del'){
			      layer.confirm('你确定要离职员工“'+data.e_truename+'”吗', function(index){
			    	  $.post('${pageContext.request.contextPath}/clientAction_findByEid',{e_id : id},function(data){
			        	  if(data.result=="ok"){
			        		  location.href = "${pageContext.request.contextPath}/empAction_del?e_id="+id;
			        	  }else{
			        		  layer.open({
				         			title: '离职失败',
				         		    content: '请先交接该员工下的客户!'
				         		    ,btn: ['确定']
				         		    ,yes: function(index){
				         		      layer.close(index);
				         		    }
				         	  });
			        	  }
			          })
			          layer.close(index);
			      });
			     } else if(obj.event === 'edit'){
			     	layer.open({
						type: 2,
						title: false,
						id: 'dept_update',
						area: ['600px', '700px'],
						content: 'updateEmp.jsp'
					})
			     }
			 });
			
			//监听提交
			form.on('submit(saveDept)', function(data){
				layer.alert(JSON.stringify(data.field), {
				      title: '最终的提交信息'
				})
				return false;
			});

		})
		
	</script>
	
	<script type="text/html" id="sex">
  		{{#  if(d.e_sex == 1){ }}
    		男
  		{{#  } else { }}
    		女
 		{{#  } }}
	</script>
	<script type="text/html" id="flag">
  		{{#  if(d.e_flag == 1){ }}
    		部门主管
  		{{#  } else { }}
    		普工
  		{{#  } }}
	</script>
	<script type="text/html" id="admin">
  		{{#  if(d.e_admin == 1){ }}
    		部门主管
  		{{#  } else { }}
    		普通操作者
  		{{#  } }}
	</script>
	<script type="text/html" id="operation">
  		<a class="layui-btn layui-btn-mini" lay-event="edit"><i class="layui-icon">&#xe642;</i>修改</a>
		<a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del"><i class="layui-icon">&#x1007;</i>离职</a>
	</script>
</body>
</html>